﻿using System;
using System.ComponentModel;
using System.Drawing.Design;
using SdmxMl.UiEditors;


namespace SdmxMl.SmsImportCfg
{
    [TypeConverter(typeof(ArtefactCfg.ExpressionConverter))]
    public class ArtefactCfg
    {
        #region Internal TypeConverter
        public class ExpressionConverter : TypeConverter
        {

            public override bool GetPropertiesSupported(ITypeDescriptorContext context)
            {
                return true;
            }

            public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context,
                object value, Attribute[] attributes)
            {
                PropertyDescriptorCollection properties =
                    TypeDescriptor.GetProperties(value, attributes);

                // Changing the display order
                string[] textOrder = new string[properties.Count];
                textOrder[0] = "Row";
                textOrder[1] = "ColID";
                textOrder[2] = "ColAgencyID";
                textOrder[3] = "NameColumns";
                // Return a sorted list of properties
                return properties.Sort(textOrder);
            }
        }
        #endregion //Internal TypeConverter

        #region Properties

        private int _row;
        [DefaultValue(0)]
        [Category("Activation")]
        [RefreshProperties(RefreshProperties.Repaint)]
        [DescriptionAttribute("Defines the row number in the Excel Worksheet where the Artefact attributes are described." +
            "If information is not available, Set row number to zero and use the Artefact attributes Editor. " )]
        public int Row
        {
            get { return _row; }
            set { _row = value; }
        }

        private int _colId;
        [DefaultValue(0)]
        [Category("Attributes")]
        [DescriptionAttribute("Defines the column index in the Excel Worksheet where the Artefact id is described." +
            "This information is only used if Excel Artefact Row is activated.")]
        public int ColID
        {
            get { return _colId; }
            set { _colId = value; }
        }

        private int _colAgencyId;
        [DefaultValue(0)]
        [Category("Attributes")]
        [DescriptionAttribute("Defines the column index in the Excel Worksheet where the Artefact AgencyId is described." +
            "This information is only used if Excel Artefact Row is activated.")]
        public int ColAgencyID
        {
            get { return _colAgencyId; }
            set { _colAgencyId = value; }
        }

        private int[] _nameCols;
        [RefreshProperties(RefreshProperties.Repaint)]
        [Editor(typeof(InternationalizedColLocEditor), typeof(UITypeEditor))]
        [TypeConverter(typeof(DicoColConverter))]
        [Category("Attributes")]
        [DescriptionAttribute("Defines the set of columns index in the Excel Worksheet where the Artefact Name is given in each supported language." +
            "sets unavailable languages to zero. " +
            "This information is only used if Excel Artefact Row is activated.")]
        public virtual int[] NameColumns
        {
            get { return _nameCols; }
            set { _nameCols = value; }
        }

        private int[] _descrCols;
        [Category("Attributes")]
        [DescriptionAttribute("Defines the set of columns index in the Excel Worksheet where the Artefact Description is given in each supported language." +
            "sets unavailable languages to zero. " +
            "This information is only used if Excel Artefact Row is activated.")]
        [RefreshProperties(RefreshProperties.Repaint)]
        [Editor(typeof(InternationalizedColLocEditor), typeof(UITypeEditor))]
        [TypeConverter(typeof(DicoColConverter))]
        public virtual int[] DescriptionColumns
        {
            get { return _descrCols; }
            set { _descrCols = value; }
        }

        private int _versionCol;
        [Category("Attributes")]
        [DefaultValue(0)]
        [DescriptionAttribute("Defines the column index in the Excel Worksheet where the Artefact Version is given." +
            "If not used, the version is defaulted to 1.0" +
            "This information is only used if Excel Artefact Row is activated.")]
        public int ColVersion
        {
            get { return _versionCol; }
            set { _versionCol = value; }
        }

        private int _colValidFrom;
        [DefaultValue(0)]
        [Category("Attributes")]
        [DescriptionAttribute("Defines the column index in the Excel Worksheet where the ValidFrom date (yyyy.mm.dd) is described." +
            "This information is only used if Excel Artefact Row is activated.")]
        public int ColValidFrom
        {
            get { return _colValidFrom; }
            set { _colValidFrom = value; }
        }

        private int _colValidTo;
        [DefaultValue(0)]
        [Category("Attributes")]
        [DescriptionAttribute("Defines the column index in the Excel Worksheet where the ValidTo date (yyyy.mm.dd) is described." +
            "This information is only used if Excel Artefact Row is activated.")]
        public int ColValidTo
        {
            get { return _colValidTo; }
            set { _colValidTo = value; }
        }


        #endregion // Properties

        #region Construction

        public ArtefactCfg()
        {
            _descrCols = new int[SdmxMl.Common.LangSupport.Count];
            _nameCols = new int[SdmxMl.Common.LangSupport.Count];

        }

        #endregion //Construction

        #region String Representation

        public override string ToString()
        {
            return _row == 0 ? "unused" : "used";
        }

        #endregion
    }
}
